home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 25
/
CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso
/
CUCD
/
WWW
/
http
/
www.wirenet.co.uk
/
files
/
Dashboard2.lha
/
Dashboard2
/
AmiTCP
/
bin
/
Connect
< prev
next >
Wrap
Text File
|
1998-03-27
|
10KB
|
312 lines
/*
$VER: Connect 2.0 (26.3.98)
(c) Neil Bothwick
Connects your Amiga to the Internet, optionally
fetching news or mail and logging off again
*/
address command 'StartNet'
/* ;;; Usage
Name
Connect
Usage
Connect [MAIL|NEWS|AUTOMAIL|AUTONEWS|OFF|AUTOOFF]
Options
None: Connects to Internet
MAIL: Connects to Internet and fetches mail
NEWS: Connects to Internet and fetches news and mail
AUTOMAIL: Connects to Internet, fetches mail and disconnects
AUTONEWS: Connects to Internet, fetches news and mail and disconnects
OFF: Disconnects from Internet
AUTOOFF: Disconnects from Internet after waiting for news and mail to finish
*/
;;;
/* ;;;These are specific to your setup */
DevName = 'DEVS:Networks/ppp.device' /* Your network device */
DevUnit = 0 /* its unit number */
Interface = 'ppp'||DevUnit /* Interface name */
;;;
/* ;;;Don't change anything below here */
BinPath = 'Wirenet:bin/' /* Paths to AmiTCP commands */
ThorPath = GetVar('Thor/ThorPath')
Miami = 'Miami:Miami'
StartNet = BinPath||'StartNet'
ifconfig = BinPath||'ifconfig'
route = BinPath||'route'
online = BinPath||'online'
offline = BinPath||'offline'
resolve = BinPath||'resolve'
SendEvents = BinPath||'SendEvents'
GetMail = BinPath||'Fetch Mail'
GetNews = BinPath||'Fetch All'
LogPath = 'UUSpool:Info.log'
SendProc = ThorPath||'bin/SendTCP' /* CLI process names for news and mail */
GetProc = ThorPath||'bin/GetTCP'
Unbatch = BinPath||'ParseThor'
cr = '0a'x
options results
address command
arg opt
;;;
/* ;;;Main routine */
if pos(upper(getclip('TCPstack')),'ONYESTRUE1') > 0 then TCPstack = 1
else TCPstack = 0
if getclip('IPAddress') = '0.0.0.0' then AcctType = 'Dynamic'
else AcctType = 'Static'
select
when opt = '' then call Connect
when opt = 'OPEN' then call Connect
when opt = 'MAIL' then do
call Connect
call DoMail
end
when opt = 'NEWS' then do
call Connect
call DoNews
end
when opt = 'AUTOMAIL' then do
call Connect
call DoMail
'Wait 20'
call Auto
call Disconnect
end
when opt = 'AUTONEWS' then do
call Connect
call DoNews
'Wait 20'
call Auto
call Disconnect
end
when opt = 'OFF' then call Disconnect
when opt = 'AUTOOFF' then do
call Auto
call Disconnect
end
otherwise call BadArgs
end
;;;
exit
/* Procedures */
/* ;;;Establish connection */
Connect:
StartNet
if CheckOnline() > 0 then do
if rtezrequest('You are already online'cr'Send outstanding events?','_Yes|_No','Connect','rt_reqpos = reqpos_centerscr') = 1 then do
'CheckCmd >NIL:' SendProc
if RC = 0 then call rtezrequest('Already sending events',' OK ','Connect','rt_reqpos = reqpos_centerscr')
else 'run' SendEvents
end
exit
end
if exists('Wirenet:UserScripts/PreConnect') then address command 'Wirenet:UserScripts/PreConnect'
if TCPstack = 0 then do
call MakeDialScript()
online Interface
if RC > 0 then call ConnectionFailed
ifconfig 'lo0 localhost'
ifconfig Interface '$ppp0IPLocal $ppp0IPRemote'
if AcctType = 'Dynamic' then do /* Set up for dynamic account */
address 'AMITCP' 'ADD HOST' getvar('ppp0IPLocal') getclip('HostName')
route 'add $ppp0IPLocal localhost'
end
route 'add default $ppp0IPRemote'
call WriteLog('Connection made to' GetVar('ppp0IPRemote'))
end
else do
address 'MIAMI.1' 'ONLINE'
if CheckOnline() = 0 then call ConnectionFailed
call WriteLog('Connection made')
end
if exists('Wirenet:UserScripts/PostConnect') then address command 'Wirenet:UserScripts/PostConnect'
options failat 21
'delete >NIL: ENV:sana2/ppp.#?'
'delete >NIL: ENV:sana2/DialScript'
options failat 10
'run' SendEvents
'Run >NIL: GetStatus'
return
;;;
/* ;;;Close connection */
Disconnect:
if exists('Wirenet:UserScripts/PreDisconnect') then address command 'Wirenet:UserScripts/PreDisconnect'
if TCPstack = 0 then do
ifconfig interface 'down'
offline Interface
route 'delete >NIL: $ppp0IPLocal'
route 'delete >NIL: default'
end
else do
address 'MIAMI.1' 'OFFLINE'
end
call WriteLog('Connection closed')
Unbatch
if exists('Wirenet:UserScripts/PostDisconnect') then address command 'Wirenet:UserScripts/PostDisconnect'
return
;;;
/* ;;;Start mail download */
DoMail:
'run >NIL:' GetMail
call WriteLog('Mail download started')
return
;;;
/* ;;;Start mail and news download */
DoNews:
'Run >NIL:' GetNews
call WriteLog('News download started')
return
;;;
/* ;;;Wait for mail and news processes to stop */
Auto:
say 'Waiting for news/mail to finish'
call WaitToEnd(SendProc GetProc 'GetTCP' 'SendTCP' 'ncftp' 'tcpdl' 'httpj' 'GrabHTTP')
'Wait 2'
call WaitToEnd(SendProc GetProc 'GetTCP' 'SendTCP' 'ncftp' 'tcpdl' 'httpj' 'GrabHTTP')
return
;;;
/* ;;;Give usage information */
BadArgs:
say
say 'Usage: Connect [MAIL|NEWS|AUTOMAIL|AUTONEWS|OFF|AUTOOFF]'
say
say ' None: Connects to Internet'
say ' MAIL: Connects to Internet and fetches mail'
say ' NEWS: Connects to Internet and fetches news and mail'
say ' AUTOMAIL Connects to Internet, fetches mail and disconnects'
say ' AUTONEWS: Connects to Internet, fetches news and mail and disconnects'
say ' OFF: Disconnects from Internet'
say ' AUTOOFF: Disconnects from Internet after waiting for news and mail to finish'
say
exit
;;;
/* ;;;Write line in logfile */
WriteLog: procedure expose LogPath
parse arg msg
LogEntry = left(date('W'),3) date() time() msg
say LogEntry
if ~open(log,LogPath,'A') then do
if ~open(log,LogPath,'W') then return
end
call writeln(log,LogEntry)
call close(log)
return
;;;
/* ;;;Wait for the specified process to finish */
WaitToEnd: procedure
parse arg Processes
procs = words(Processes)
do i = 1 to procs
parse var Processes Process.i Processes
end
do until Busy = FALSE
Busy = FALSE
do i = 1 to procs
'CheckCmd >NIL:' Process.i
if RC = 0 then do
Busy = TRUE
'Wait 3'
end
end
end
return
;;;
/* ;;;Report connection failure */
ConnectionFailed:
call WriteLog('Connection attempt failed')
ExitMsg('Your internet connection has failed')
return
;;;
/* ;;;Exit with message */
ExitMsg:
parse arg ErrMsg
say(ErrMsg)
exit
return
;;;
/* ;;;Create dialscript and ppp0.config */
MakeDialScript:
/* Create DialScript */
if ~open('ds','ENV:sana2/DialScript','W') then call ExitMsg('Failed to create dialscript')
call writeln('ds','# Dialer Script (change to echo off if you do not want echoing)')
call writeln('ds','echo on')
call writeln('ds','abort "NO DIALTONE"')
call writeln('ds','redial "BUSY" "NO CARRIER" "NO ANSWER"')
call writeln('ds','redialdelay 300')
call writeln('ds','timeout 500')
call writeln('ds','# Initialise modem...')
call writeln('ds','send "'||getclip('ModemInit')||'"')
call writeln('ds','wait "OK"')
call writeln('ds','delay 15')
call writeln('ds','# Send dial command...')
call writeln('ds','send "'||getclip('ModemDial')||getclip('PopNum')||'"')
call writeln('ds','# ... and wait for connection.')
call writeln('ds','timeout 1600')
call writeln('ds','wait "CONNECT"')
if pos(upper(getclip('UsePAP')),'ONYESTRUE1') > 0 then do
papcfg = 'ENV:sana2/ppp.'time(s)
if ~open('pc',papcfg,'W') then call ExitMsg('Failed to create pap config')
call writeln('pc',getclip('NodeName') getclip('Password'))
call close('pc')
end
else do
call writeln('ds','send ""')
call writeln('ds','# At login: prompt send nodename')
call writeln('ds','wait "ogin:"')
call writeln('ds','send "'||getclip('NodeName')||'"')
call writeln('ds','# At Password: prompt send password')
call writeln('ds','wait "assword:"')
call writeln('ds','echo off')
call writeln('ds','send "'||getclip('Password')||'"')
call writeln('ds','echo on')
call writeln('ds','# Wait for Service: prompt and then send PPP')
call writeln('ds','wait "ervice:"')
call writeln('ds','send "PPP"')
call writeln('ds','# Wait for start string')
call writeln('ds','wait "MTU"')
call writeln('ds','send " "')
call writeln('ds','# Connected!')
end
call close('ds')
/* Create PPP config file */
if ~open(pppcfg,'ENV:sana2/ppp0.config','w') then ExitMsg('Failed to create ppp configuration')
call writech(pppcfg,getclip('ModemDev')' ')
call writech(pppcfg,getclip('ModemSpeed')' ')
call writech(pppcfg,getclip('IPAddress')' ')
call writech(pppcfg,'DialScript ENV:sana2/DialScript ')
call writech(pppcfg,'MTU='getclip('MTU')' ')
call writech(pppcfg,getclip('PPPoptions'))
if pos(upper(getclip('UsePAP')),'ONYESTRUE1') > 0 then call writech(pppcfg,' PAP='papcfg','getclip('NodeName'))
if getclip('DialWindow') > '' then call writech(pppcfg,' DIALWINDOW ' getclip('DialWindow'))
if getclip('Gateway') > '' then call writech(pppcfg,' REMOTEIP' getclip('Gateway'))
call close(pppcfg)
return
;;;
/* ;;; Check if online */
CheckOnline:
if TCPstack then do
address 'MIAMI.1' 'ISONLINE'
return RC
end
else
'ifcheck >NIL:' Interface
return (RC=0)
end
;;;